

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Source: i18n/index.js | Source: i18n/index.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="styles/prettify-jsdoc.css">
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/tui-doc.css">

    
</head>
<body>
<nav class="lnb" id="lnb">
    <div class="logo" style="">
        
            <img src="img/toast-ui.png" width="100%" height="100%">
        
    </div>
    <div class="title">
        <h1><a href="index.html" class="link">Source: i18n/index.js</a></h1>
        
    </div>
    <div class="search-container" id="search-container">
        <input type="text" placeholder="Search">
        <ul></ul>
    </div>
    
    <div class="lnb-api hidden"><h3>Modules</h3><ul><li><a href="module-app.html">app</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:app_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-app.html#btnShowControl">btnShowControl</a></li><li><a href="module-app.html#initListener">initListener</a></li></ul></div></li><li><a href="module-article-card.html">article-card</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:article-card_sub"></div></li><li><a href="module-article-detail.html">article-detail</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:article-detail_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-article-detail.html#backToHome">backToHome</a></li><li><a href="module-article-detail.html#fetchArticleDetailAndProduct">fetchArticleDetailAndProduct</a></li><li><a href="module-article-detail.html#getArticleId">getArticleId</a></li></ul></div></li><li><a href="module-article-item.html">article-item</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:article-item_sub"></div></li><li><a href="module-article-module.html">article-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:article-module_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-article-module.html#watchDetail">watchDetail</a></li></ul></div></li><li><a href="module-back.html">back</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:back_sub"></div></li><li><a href="module-banner-module.html">banner-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:banner-module_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-banner-module.html#handleClick">handleClick</a></li></ul></div></li><li><a href="module-bestseller-module.html">bestseller-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:bestseller-module_sub"></div></li><li><a href="module-bestseller-product-card.html">bestseller-product-card</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:bestseller-product-card_sub"></div></li><li><a href="module-detail-recommend-module.html">detail-recommend-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:detail-recommend-module_sub"></div></li><li><a href="module-discovery.html">discovery</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:discovery_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-discovery.html#fetchArticles">fetchArticles</a></li><li><a href="module-discovery.html#handleClick">handleClick</a></li><li><a href="module-discovery.html#infiniteHandler">infiniteHandler</a></li><li><a href="module-discovery.html#isLastPage">isLastPage</a></li></ul></div></li><li><a href="module-grid-navs.html">grid-navs</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:grid-navs_sub"></div></li><li><a href="module-header.html">header</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:header_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-header.html#handleClick">handleClick</a></li></ul></div></li><li><a href="module-index.html">index</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:index_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-index.html#fetchModule">fetchModule</a></li><li><a href="module-index.html#isAppProtocol">isAppProtocol</a></li><li><a href="module-index.html#isUrlProtocol">isUrlProtocol</a></li><li><a href="module-index.html#linkTo">linkTo</a></li><li><a href="module-index.html#moduleSearch">moduleSearch</a></li><li><a href="module-index.html#readMockThemeName">readMockThemeName</a></li></ul></div></li><li><a href="module-more-product-card.html">more-product-card</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:more-product-card_sub"></div></li><li><a href="module-navs-module.html">navs-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:navs-module_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-navs-module.html#linkTo">linkTo</a></li></ul></div></li><li><a href="module-recommend-product.html">recommend-product</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:recommend-product_sub"></div></li><li><a href="module-recommend-product-module.html">recommend-product-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:recommend-product-module_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-recommend-product-module.html#lineThroughPrice">lineThroughPrice</a></li></ul></div></li><li><a href="module-single-product.html">single-product</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:single-product_sub"></div></li><li><a href="module-single-product-module.html">single-product-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:single-product-module_sub"></div></li><li><a href="module-special-product.html">special-product</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:special-product_sub"></div></li><li><a href="module-special-product-module.html">special-product-module</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:special-product-module_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-special-product-module.html#lineThroughPrice">lineThroughPrice</a></li></ul></div></li><li><a href="module-title.html">title</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:title_sub"></div></li><li><a href="module-views.html">views</a><button type="button" class="hidden toggle-subnav btn btn-link">  <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:views_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-views.html#backToHome">backToHome</a></li><li><a href="module-views.html#fetchMoreProducts">fetchMoreProducts</a></li><li><a href="module-views.html#parseUrlParams">parseUrlParams</a></li><li><a href="module-views.html#validateParams">validateParams</a></li></ul></div></li></ul></div><div class="lnb-api hidden"><h3>Global</h3><ul><li><a href="global.html#$t">$t</a></li><li><a href="global.html#appHandle">appHandle</a></li><li><a href="global.html#axiosRequestReject">axiosRequestReject</a></li><li><a href="global.html#axiosRequestResolve">axiosRequestResolve</a></li><li><a href="global.html#axiosResponseReject">axiosResponseReject</a></li><li><a href="global.html#axiosResponseResolve">axiosResponseResolve</a></li><li><a href="global.html#conversionTime">conversionTime</a></li><li><a href="global.html#current_locale">current_locale</a></li><li><a href="global.html#delay">delay</a></li><li><a href="global.html#deleteEmptyValue">deleteEmptyValue</a></li><li><a href="global.html#formaturl">formaturl</a></li><li><a href="global.html#getCurrentDate">getCurrentDate</a></li><li><a href="global.html#getCurrentLocale">getCurrentLocale</a></li><li><a href="global.html#getHiddenProp">getHiddenProp</a></li><li><a href="global.html#getLanguage">getLanguage</a></li><li><a href="global.html#getLanguageForBackEnd">getLanguageForBackEnd</a></li><li><a href="global.html#getLanguageOptions">getLanguageOptions</a></li><li><a href="global.html#getUploadImage">getUploadImage</a></li><li><a href="global.html#getVisibilityChangeEventName">getVisibilityChangeEventName</a></li><li><a href="global.html#i18n">i18n</a></li><li><a href="global.html#imgPreLoad">imgPreLoad</a></li><li><a href="global.html#importStyle">importStyle</a></li><li><a href="global.html#isContained">isContained</a></li><li><a href="global.html#isHidden">isHidden</a></li><li><a href="global.html#loading_toast">loading_toast</a></li><li><a href="global.html#messages">messages</a></li><li><a href="global.html#parseLanguageParameter">parseLanguageParameter</a></li><li><a href="global.html#parseQueryString">parseQueryString</a></li><li><a href="global.html#resizeModal">resizeModal</a></li><li><a href="global.html#setLanguageOptions">setLanguageOptions</a></li><li><a href="global.html#setLocale">setLocale</a></li><li><a href="global.html#setMinHeightToInnerHeight">setMinHeightToInnerHeight</a></li><li><a href="global.html#startLoading">startLoading</a></li></ul></div>
</nav>
<div id="resizer"></div>

<div class="main" id="main">
    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/*
 * @Description: 多语言文件
 * @Author: kanglin
 * @Date: 2018-05-31 14:33:47
 * @Copyright: Created by Panxsoft.
 */
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import { parseLanguageParameter } from 'src/utils/helper';
import zhCN from './languages/zh-cn';
import enUS from './languages/en-us';

Vue.use(VueI18n);

/**
 *  读取本地语言
 */
const current_locale = parseLanguageParameter(); // getCurrentLocale();
// Vue.config.lang = current_locale;
/**
 *  语言文件配置
 */
const messages = {
	'zh-CN': zhCN,
	'en-US': enUS,
};

/**
 * 配置 i18n
 */
export const i18n = new VueI18n({
	locale: current_locale,
	// fallbackLocale: 'zh-CN',
	messages,
});

/**
 * 切换语言
 * @param {string} locale
 */
export function setLocale(locale) {
	// Vue.config.lang = locale; // iview 的语言切换方式
	i18n.locale = locale; // i18n 的切换方式
}

/**
 * 翻译
 * @param {string} path
 * @param {object} options
 */
export function $t(path, options) {
	return i18n.t(path, options);
}

/**
 *  获取当前语言
 * @return {string} language
 */
export function getLanguage() {
	return i18n.locale;
}

const language = {
	options: 'zh-CN',
};

/**
 * 设置语言
 *  @return {string} language
 */
export function setLanguageOptions(name) {
	language.options = name;
}

/**
 * 获取语言选项
 *  @return {string} language
 */
export function getLanguageOptions() {
	return language.options;
}

/**
 *  后端的英文是 en , 中文是 zh-CN.
 */
export function getLanguageForBackEnd() {
	const MAP = { 'en-US': 'en-gb', 'zh-CN': 'zh-cn' };
	const lang = getLanguage();
	return MAP[lang] || 'zh-cn';
}
</code></pre>
        </article>
    </section>




</div>

<footer>
    <img class="logo" src="img/toast-ui.png" style="">
    <div class="footer-text">NHN Entertainment. Frontend Development Lab</div>
</footer>
<script>prettyPrint();</script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tui-doc.js"></script>
<script src="scripts/linenumber.js"></script>

    <script>
        var id = '_sub'.replace(/"/g, '_');
        var selectedApi = document.getElementById(id); // do not use jquery selector
        var $selectedApi = $(selectedApi);

        $selectedApi.removeClass('hidden');
        $selectedApi.parent().find('.glyphicon').removeClass('glyphicon-plus').addClass('glyphicon-minus');
        showLnbApi();
    </script>

</body>
</html>
